package com.wicket.okrapp.biz.service.nb;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.github.pagehelper.Page;
 import com.wicket.okrapp.biz.service.dto.common.CycleStageDataDto;
 import com.wicket.okrapp.common.util.CommonFunctionHelper;
 import org.springframework.stereotype.Service;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import com.wicket.okrapp.biz.service.dto.req.AddPicSingleSetDataEntryReqDto;
import com.wicket.okrapp.biz.service.dto.res.AddPicSingleSetDataEntryRespDto;

 import java.lang.reflect.Field;
 import java.util.*;

 import com.wicket.okrapp.biz.service.dto.req.AddCutStringReqDto;
import com.wicket.okrapp.biz.service.dto.res.AddCutStringRespDto;
import com.wicket.okrapp.biz.service.dto.req.TransitionCycleStageDataColumnToRowReqDto;
import com.wicket.okrapp.biz.service.dto.res.TransitionCycleStageDataColumnToRowRespDto;
import com.wicket.okrapp.biz.service.dto.req.ObtainReceiveFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ObtainReceiveFieldRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementPicDataSetSingleEntryReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementPicDataSetSingleEntryRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementAccessParameterBizFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementAccessParameterBizFieldRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementPicSingleSetDataEntryReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementPicSingleSetDataEntryRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementAcceptFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementAcceptFieldRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementElevenReceivingFieldReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementElevenReceivingFieldRespDto;
import com.wicket.okrapp.biz.service.dto.req.ImplementObtainPageTotalsReqDto;
import com.wicket.okrapp.biz.service.dto.res.ImplementObtainPageTotalsRespDto;

/**
 * @author ： 手工接入方法
 * @since 2022/5/28 15:32
 *
 *
 * @version 1.0
 */
@Service
public class NbCycleStageData {
/**
      * code:objectToData
      * name:M执行图片单条转数据集
      * desc:undefined
      * gen by moon at 8/17/2022, 12:14:32 AM
      * 
      **/
     @Trace(operationName = "M执行图片单条转数据集")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public AddPicSingleSetDataEntryRespDto addPicSingleSetDataEntry(AddPicSingleSetDataEntryReqDto reqDto) {
         AddPicSingleSetDataEntryRespDto retData = new AddPicSingleSetDataEntryRespDto();
         if(ObjectUtil.isEmpty(reqDto) || ObjectUtil.isEmpty(reqDto.getDatasetField())){
             return retData;
         }
         String[] fileList = reqDto.getDatasetField().split(",");
         if(ObjectUtil.isEmpty(fileList)){
             return retData;
         }
         List<String> retList = Arrays.asList(fileList);
         List<String> retNewList = new ArrayList<>();
         for(String one : retList){
             if(one.equals("--")){
                 continue;
             }
             retNewList.add(CommonFunctionHelper.getFilePath(one));
         }
         retData.setPicSingleSetDataEntryList(retNewList);
        return retData;
      }
/**
      * code:cutString
      * name:M3-截取字符串前N个字符
      * desc:undefined
      * gen by moon at 9/6/2022, 10:10:54 PM
      * 
      **/
     @Trace(operationName = "M3-截取字符串前N个字符")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public AddCutStringRespDto addCutString(AddCutStringReqDto reqDto) {
         //当前实现是错误的，因为设计插件少传 截取多少个字符的参数
         AddCutStringRespDto retData = new AddCutStringRespDto();
         if(reqDto.getInputNum().intValue() > reqDto.getOriginalString().length()){
             retData.setCutString(reqDto.getOriginalString());
         }else{
             retData.setCutString(reqDto.getOriginalString().substring(0,reqDto.getInputNum().intValue()));
         }
        return retData;
      }
/**
      * code:columnToRow
      * name:M3-转换周期阶段资料列转行（特殊方法）
      * desc:undefined
      * gen by moon at 9/20/2022, 10:55:24 PM
      *
      **/
     @Trace(operationName = "M3-转换周期阶段资料列转行（特殊方法）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public TransitionCycleStageDataColumnToRowRespDto transitionCycleStageDataColumnToRow(TransitionCycleStageDataColumnToRowReqDto reqDto) {
         TransitionCycleStageDataColumnToRowRespDto retData = new TransitionCycleStageDataColumnToRowRespDto();
         Field[] declaredFields = TransitionCycleStageDataColumnToRowRespDto.class.getDeclaredFields();
         Map<String,Field> tarGetValueIndex = new HashMap<>();
         for (Field field : declaredFields) {
             tarGetValueIndex.put(field.getName(),field);
         }
         for(CycleStageDataDto oneItem : reqDto.getCycleStageDataList()){
             Field tarGetField = tarGetValueIndex.get(CommonFunctionHelper.underlineToHump(oneItem.getStageContentType()));
             if(tarGetField!=null){
                 try {
                     tarGetField.setAccessible(true);
                     tarGetField.set(retData,oneItem.getStageData());
                 } catch (IllegalAccessException e) {
                     e.printStackTrace();
                 }
             }

         }
         return retData;
      }
/**
      * code:receptionService
      * name:M3-获取接收字段（特殊方法）
      * desc:undefined
      * gen by moon at 12/15/2022, 5:12:49 PM
      *
      **/
     @Trace(operationName = "M3-获取接收字段（特殊方法）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ObtainReceiveFieldRespDto obtainReceiveField(ObtainReceiveFieldReqDto reqDto) {
        return BeanUtil.toBean(reqDto,ObtainReceiveFieldRespDto.class);
      }
/**
      * code:dataToObject
      * name:M执行图片数据集转单条
      * desc:undefined
      * gen by moon at 12/17/2022, 4:38:28 AM
      * 
      **/
     @Trace(operationName = "M执行图片数据集转单条")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementPicDataSetSingleEntryRespDto implementPicDataSetSingleEntry(ImplementPicDataSetSingleEntryReqDto reqDto) {
         ImplementPicDataSetSingleEntryRespDto retData = new ImplementPicDataSetSingleEntryRespDto();
         if(reqDto.getPicDataSetSingleEntryList()==null || reqDto.getPicDataSetSingleEntryList().size()==0){
             return retData;
         }
         String str = "";
         for(String one : reqDto.getPicDataSetSingleEntryList()){
             if(one.equals("--")){
                 continue;
             }
             one = CommonFunctionHelper.replaceFilePath(one);
             str = one + "," + str;
         }
         retData.setDatasetField(str);
         String tmpStr = retData.getDatasetField().substring(0,retData.getDatasetField().length()-1);
         retData.setDatasetField(tmpStr);
         return retData;
      }

    public static void main(String[] args) {
        ImplementPicDataSetSingleEntryReqDto req = new ImplementPicDataSetSingleEntryReqDto();
        req.getPicDataSetSingleEntryList().add("https://www.suzhi.link/SPACE/UPDATE_TASK_PROCESS/81705860010741760/png/20240123/19B5B39B399045C0B693CEEF8F9209C1.png");
        NbCycleStageData o = new NbCycleStageData();
        ImplementPicDataSetSingleEntryRespDto ret = o.implementPicDataSetSingleEntry(req);
    }
/**
      * code:receptionService
      * name:M3执行获取出入参业务字段（特殊方法）
      * desc:undefined
      * gen by moon at 3/5/2023, 6:50:45 PM
      * 
      **/
     @Trace(operationName = "M3执行获取出入参业务字段（特殊方法）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementAccessParameterBizFieldRespDto implementAccessParameterBizField(ImplementAccessParameterBizFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementAccessParameterBizFieldRespDto.class);
      }
/**
      * code:objectToData
      * name:M-将9宫格图片转数据集
      * desc:undefined
      * gen by moon at 3/25/2023, 1:08:35 PM
      *
      **/
     @Trace(operationName = "M-将9宫格图片转数据集")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementPicSingleSetDataEntryRespDto implementPicSingleSetDataEntry(ImplementPicSingleSetDataEntryReqDto reqDto) {
         ImplementPicSingleSetDataEntryRespDto retData = new ImplementPicSingleSetDataEntryRespDto();
         List<String> reqList = Arrays.asList(reqDto.getDatasetField().split(","));
         for(String one : reqList){
             retData.getPicSingleSetDataEntryList().add(CommonFunctionHelper.getFilePath(one));
         }
        return retData;
      }
/**
      * code:receptionService
      * name:M3约定为【工作周期】
      * desc:undefined
      * gen by moon at 4/15/2023, 1:20:31 AM
      * 
      **/
     @Trace(operationName = "M3约定为【工作周期】")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementAcceptFieldRespDto implementAcceptField(ImplementAcceptFieldReqDto reqDto) {
        return BeanUtil.toBean(reqDto,ImplementAcceptFieldRespDto.class);
      }
/**
      * code:receptionService
      * name:M3接收入参字段
      * desc:undefined
      * gen by moon at 6/29/2024, 4:19:16 AM
      *
      **/
     @Trace(operationName = "M3接收入参字段")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementElevenReceivingFieldRespDto implementElevenReceivingField(ImplementElevenReceivingFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto,ImplementElevenReceivingFieldRespDto.class);
      }
/**
      * code:obtainPageTotals
      * name:M3-执行获取分页总条数（特殊方法）
      * desc:undefined
      * gen by moon at 8/30/2024, 1:03:17 PM
      *
      **/
     @Trace(operationName = "M3-执行获取分页总条数（特殊方法）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementObtainPageTotalsRespDto implementObtainPageTotals(ImplementObtainPageTotalsReqDto reqDto) {
         ImplementObtainPageTotalsRespDto retData = new ImplementObtainPageTotalsRespDto();
         retData.setTotals(0L);
         Page<?> page =  CommonFunctionHelper.getBaseInfoFromLocal().getPageInfo();
         if(page!=null){
             retData.setTotals(page.getTotal());
         }
         return retData;
      }
    //手工接入方法
}
